package com.example.image.glide

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.MultiTransformation
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import jp.wasabeef.glide.transformations.BlurTransformation
import jp.wasabeef.glide.transformations.RoundedCornersTransformation

object GlideImgLoader {
    //普通图片
    fun loadImage(context: Context, url:String, imageView: ImageView){
        Glide.with(context)
            .load(url)
            .error(com.luck.picture.lib.R.drawable.ps_gif_tag)
            .placeholder(com.luck.picture.lib.R.drawable.ps_gif_tag)
            .skipMemoryCache(false)
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .into(imageView)
    }
    //圆形图片
    fun loadBoundImage(context: Context, url: String, radio: Int, imageView: ImageView) {
        Glide.with(context)
            .load(url)
            .placeholder(ColorDrawable(Color.GRAY))
            .error(ColorDrawable(Color.YELLOW))
            .skipMemoryCache(true)
            .transform(CenterCrop(), RoundedCorners(radio))
            .dontAnimate()
            .into(imageView)
    }
    //圆角图片
    fun loadCircleImage(context: Context, url: String, imageView: ImageView) {
        Glide.with(context)
            .load(url)
            .placeholder(ColorDrawable(Color.GRAY))
            .error(ColorDrawable(Color.YELLOW))
            .skipMemoryCache(false)
            .diskCacheStrategy(DiskCacheStrategy.RESOURCE) //磁盘缓存策略：NONE, ALL，DATA，RESOURCE，AUTOMATIC
            .transform(CenterCrop(), CircleCrop())
            .dontAnimate()
            .into(imageView)
    }

    //加载本地
    fun LoadResImage(view:View,resId:Int,imgView:ImageView){
        Glide.with(view)
            .load(resId)
            .skipMemoryCache(false)
            .transform(CenterCrop())
            .into(imgView)
    }
    /**
     *毛玻璃效果
     */
    fun loadBlurImage(context:Context,url:String,imageView: ImageView){
        Glide.with(context)
            .load(url)
            .placeholder(ColorDrawable(Color.GRAY))
            .error(ColorDrawable(Color.YELLOW))
            .thumbnail(0.5F)//设置缩略图
            .skipMemoryCache(false)//跳过内存缓存
            .diskCacheStrategy(DiskCacheStrategy.RESOURCE)//磁盘缓存策略：NONE，ALL，DATA，RESOURCE，AUTOMATIC
            .apply(RequestOptions.bitmapTransform(MultiTransformation<Bitmap>(
                BlurTransformation(10,3),
                RoundedCornersTransformation(128,0,RoundedCornersTransformation.CornerType.BOTTOM)
            )))
            .into(imageView)
    }




}